﻿using Padsurface.CoreAudio.Enumerations;
using System;
using System.Runtime.InteropServices;

namespace Padsurface.CoreAudio.Components.WASAPI.Interfaces
{
    /// <summary>
    /// The IAudioCaptureClient interface enables a client to read input data from a capture endpoint buffer
    /// </summary>
    [Guid(ComIIDs.IAudioCaptureClientIID), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IAudioCaptureClient
    {
        /// <summary>
        /// Retrieves a pointer to the next available packet of data in the capture endpoint buffer
        /// </summary>
        /// <param name="data">Pointer to a pointer variable into which the method writes the starting address of the next data packet that is available for the client to read</param>
        /// <param name="numFramesToRead">Pointer to a UINT32 variable into which the method writes the frame count (the number of audio frames available in the data packet). 
        /// The client should either read the entire data packet or none of it.</param>
        /// <param name="bufferFlags">Pointer to a DWORD variable into which the method writes the buffer-status flags</param>
        /// <param name="devicePosition">Pointer to a UINT64 variable into which the method writes the device position of the first audio frame in the data packet. 
        /// The device position is expressed as the number of audio frames from the start of the stream. 
        /// This parameter can be NULL if the client does not require the device position.</param>
        /// <param name="qpcPosition">Pointer to a UINT64 variable into which the method writes the value of the performance counter 
        ///     at the time that the audio endpoint device recorded the device position of the first audio frame in the data packet. 
        /// The method converts the counter value to 100-nanosecond units before writing it to *pu64QPCPosition. 
        /// This parameter can be NULL if the client does not require the performance counter value.</param>
        /// <returns>HRESULT: If the method succeeds, it returns S_OK</returns>
        int GetBuffer(
            out IntPtr data,
            out UInt32 numFramesToRead,
            out AudioClientBufferFlags bufferFlags,
            out UInt64 devicePosition,
            out UInt64 qpcPosition);

        /// <summary>
        /// Releases the buffer
        /// </summary>
        /// <param name="numFramesRead">The number of audio frames that the client read from the capture buffer. 
        /// This parameter must be either equal to the number of frames in the previously acquired data packet or 0.</param>
        /// <returns>HRESULT: If the method succeeds, it returns S_OK</returns>
        int ReleaseBuffer(uint numFramesRead);

        /// <summary>
        /// Retrieves the number of frames in the next data packet in the capture endpoint buffer
        /// </summary>
        /// <param name="numFramesInNextPacket">Pointer to a UINT32 variable into which the method writes the frame count (the number of audio frames in the next capture packet)</param>
        /// <returns>HRESULT: If the method succeeds, it returns S_OK</returns>
        int GetNextPacketSize(out int numFramesInNextPacket);
    }
}